<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<html>
<head>
<script type="text/javascript" src="../js/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
	$(document).ready(
			function() {
				
				/*
				//$("#DROPID").value="1";
				if (getURLParameter("DROPID") != "null"){
					var a = getURLParameter("DROPID");
					//alert(getURLParameter("DROPID"));
					$("#DROPID").value=getURLParameter("DROPID");
					
					$.getJSON("qservice.jsp", { dropid: a }, function(data, state) {

								if(data.jsonChildarray.length===0)
									alert("初盤流水號有問題!!");
								
								$("#mytable").find("tr:gt(0)").remove();
								$.each(data.jsonChildarray, function(i, data) {
									$("#mytable").append(
											'<tr> <td>' + i + '</td><td name="LOC" >' 
													+ data.LOC + '</td><td name="SKU" >'
													+ data.SKU + '</td><td name="DESCR" >'
													+ data.DESCR + '</td><td name="UPCCODE" >'
													+ data.UPCCODE + '</td><td name="LOTTBALOE05" >'
													+ data.LOTTBALOE05 + '</td><td name="CASECNT" align="right">'
													+ data.CASECNT + '</td><td name="QTY" align="right">'
													+ data.QTY + '</td> <td><input type="text" style="width:100px;" STYLE="text-align:right" name="COUNTQTY" /></td>'
													+ '<input type="hidden" name="LOC" value="' 
													+ data.LOC + '">'
													+ '<input type="hidden" name="SKU" value="' 
													+ data.SKU + '">'
													+ '</tr>');
								});
								
								$("#DROPID").value=getURLParameter("DROPID");
								
							});
				}

*/
				$("#DROPID").change(
						function() {

							/******************
							alert('Handler for .change() called.');
							
							/******************/
							//$.getJSON("qservice.jsp", { dropid: $("#DROPID").val() }, function(data, state) {
							$.getJSON("qservice.jsp", { dropid: $("#DROPID").val() }, function(data, state) {

								/*****************debug/
								alert(data.jsonChildarray.length);
								/******************/
								if(data.jsonChildarray.length===0)
									alert("初盤流水號有問題!!");
								
								$("#mytable").find("tr:gt(0)").remove();
								$.each(data.jsonChildarray, function(i, data) {
									$("#mytable").append(
											'<tr> <td>' + i + '</td><td name="LOC" >' 
													+ data.LOC + '</td><td name="SKU" >'
													+ data.SKU + '</td><td name="DESCR" >'
													+ data.DESCR + '</td><td name="UPCCODE" >'
													+ data.UPCCODE + '</td><td name="LOTTBALOE05" >'
													+ data.LOTTBALOE05 + '</td><td name="CASECNT" align="right">'
													+ data.CASECNT + '</td><td name="QTY" align="right">'
													+ data.QTY + '</td> <td><input type="text" style="width:100px;" STYLE="text-align:right" name="COUNTQTY" /></td>'
													+ '<input type="hidden" name="LOC" value="' 
													+ data.LOC + '">'
													+ '<input type="hidden" name="SKU" value="' 
													+ data.SKU + '">'
													+ '</tr>');
								});
								/******************/
								//if ( k == -1 ){}
								
							});
							/******************/
						});
						
				
				$('#jsonForm').ajaxForm({
					// dataType identifies the expected content type of the server response 
					dataType : 'json',

					// success identifies the function to invoke when the server response 
					// has been received 
					success : processJson
				});

			});

	function processJson(data) {
		// 'data' is the json object returned from the server 
		alert(data.message);
	}
	
	
	function addrow() {
		//var form_url = $("#myform").attr("action");
		//alert("Before - action=" + form_url);       

		$("#myform").attr("action", "addrow.jsp");
		//alert("After - action = "+$("#myform").attr("action"));
		//submit the form
		$("#myform").submit();
	}
	
	function getURLParameter(name) {
		return decodeURI((RegExp(name + '=' + '(.+?)(&|$)').exec(
				location.search) || [ , null ])[1]);
	}
</script>
</head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">


<body>


	<form id='myform' action="updatetable.jsp" method="post" ALIGN="CENTER" >
		<table ALIGN="CENTER"><tr>
			<td Width="50"></td>
			<td Width="100"><input id="DROPID" type="text" name="DROPID" /></td>
			<td Width="100"></td>
			<td Width="100"></td>
			<td Width="100"></td>
			<td Width="100"></td>
			<td Width="100"></td>
			<td Width="100"></td>
			<td Width="100"></td>
		</tr>
		</table>
		<table id="mytable"  border =1 ALIGN="CENTER">
			<tr>
				<th Width="50">序號</th>
				<th Width="100">儲位</th>
				<th Width="100">品名</th>
				<th Width="100">商品代碼</th>
				<th Width="100">UPC</th>
				<th Width="100">效期</th>
				<th Width="100">箱入數</th>
				<th Width="100">庫存數</th>
				<th Width="100">初盤數量</th>
			</tr>
		</table>
		<table ALIGN="CENTER">
		<tr>
		<td Width="50"></td><td Width="100"></td><td Width="100"></td><td Width="100"></td><td Width="100"></td><td Width="100"></td><td Width="100"><input type="button" onclick="addrow()" value="新增" /></td><td Width="100"><input type="submit" value="確認" /></td>
		</tr>
		</table>
	</form>
</body>
</html>

